package functional_thinking._2;

import java.util.HashSet;
import java.util.Set;

public class ImpNumberClassifierNoCacheSimple {

	private int _number;

	public ImpNumberClassifierNoCacheSimple(int targetNumber) {
		_number = targetNumber;
	}

	public boolean isFactor(int potential) {
		return _number % potential == 0;
	}

	public Set<Integer> getFactors() {
		Set<Integer> factors = new HashSet<>();
		factors.add(1);
		factors.add(_number);
		for (int i = 2; i < _number; i++) {
			if (isFactor(i)) {
				factors.add(i);
			}
		}
		return factors;
	}

	public int aliquoSum() {
		int sum = 0;
		for (int i : getFactors()) {
			sum += i;
		}
		return sum - _number;
	}

	public boolean isPerfect() {
		return aliquoSum() == _number;
	}

	public boolean isAbundant() {
		return aliquoSum() > _number;
	}

	public boolean isDeficient() {
		return aliquoSum() < _number;
	}

	public static void main(String[] args) {
		// 6 28
		for (int i = 0; i < 1000000; i++) {
			ImpNumberClassifierNoCacheSimple simple = new ImpNumberClassifierNoCacheSimple(i);
			if (simple.isPerfect()) {
				System.out.println(i);
			}
		}
	}

}
